﻿namespace HPSocketLibrary.Devices
{

    /// <summary>
    /// 消息头
    /// </summary>
    public class MtIntfaceMsgFormat_Head
    {
        /// <summary>
        /// 设备序列号 e6cd951b7120
        /// </summary>
        public static string serialNoStr = "e6cd951b7120";
        /// <summary>
        /// 厂商名称 snbc
        /// </summary>
        public static string _vendor = "hnxz";
        /// <summary>
        /// 设备型号 snbc_aps_01
        /// </summary>
        public static string _model = "xzfyj_01";

        public static string _deviceID = "";
        /// <summary>
        /// 消息类型 
        /// 收到命令  requeset
        /// 反馈命令  response
        /// </summary>
        public string type { get; set; }
        /// <summary>
        /// 消息名称
        /// </summary>
        public string interfaceName { get; set; }
        /// <summary>
        /// 请求的 Id（唯一标识）
        /// </summary>
        public string request_id { get; set; } = DateTime.Now.Ticks.ToString();
        /// <summary>
        ///  版本号（当前版本写 1.0）
        /// </summary>
        public string version { get; set; }
        /// <summary>
        /// 状态码
        /// </summary>
        public int status_code { get; set; }
        /// <summary>
        /// 厂商信息（目前填写 snbc）
        /// </summary>
        public string vendor { get; set; }
        /// <summary>
        /// model 信 息 （ 目 前 填 写snbc_aps_01）
        /// </summary>
        public string model { get; set; }
        /// <summary>
        /// 设别序列号，唯一标识该设备
        /// </summary>
        public string serialNo { get; set; }


        public static MtIntfaceMsgFormat_Head CreateDefaultRequestMsgHead(MtSSLMsgType msgType, bool isRequest)
        {
            MtIntfaceMsgFormat_Head head = new MtIntfaceMsgFormat_Head()
            {
                version = "1.0",
                type = isRequest ? "request" : "response",
                // request_id = Guid.NewGuid().ToString("N"),
                request_id = DateTime.Now.Ticks.ToString(),
                interfaceName = GetMsgTypeInterFaceName(msgType),
                status_code = 0,
                vendor = _vendor,
                model = _model,
                serialNo = serialNoStr
            };
            return head;
        }

        public static MtSSLMsgType GetMsgType(string interFaceName)
        {
            switch (interFaceName)
            {
                case "HEART_BEAT":
                    return MtSSLMsgType.HEART_BEAT;
                case "REPORT_DEVICE_STATUS":
                    return MtSSLMsgType.REPORT_DEVICE_STATUS;
                case "SYSTEM_STARTED":
                    return MtSSLMsgType.SYSTEM_STARTED;
                case "ORDER_BUTTON_STATE":
                    return MtSSLMsgType.ORDER_BUTTON_STATE;
                case "ORDER_RECEIVE":
                    return MtSSLMsgType.ORDER_RECEIVE;
                case "TEMPHUBSTATE":
                    return MtSSLMsgType.TEMPHUBSTATE;
                case "OPENBOXJOIN":
                    return MtSSLMsgType.OPENBOXJOIN;
                case "LOCKBOXJOIN":
                    return MtSSLMsgType.LOCKBOXJOIN;
                case "BOXDISPOSE":
                    return MtSSLMsgType.BOXDISPOSE;
            }

            return MtSSLMsgType.HEART_BEAT;
        }
        public static string GetMsgTypeInterFaceName(MtSSLMsgType msgType)
        {
            switch (msgType)
            {
                case MtSSLMsgType.HEART_BEAT:
                    return "HEART_BEAT";
                case MtSSLMsgType.REPORT_DEVICE_STATUS:
                    return "REPORT_DEVICE_STATUS";
                case MtSSLMsgType.SYSTEM_STARTED:
                    return "SYSTEM_STARTED";
                case MtSSLMsgType.DEVICE_STOP:
                    return "DEVICE_STOP";
                case MtSSLMsgType.DEVICE_RECOVERY:
                    return "DEVICE_RECOVERY";
                case MtSSLMsgType.ORDER_BUTTON_STATE:
                    return "ORDER_BUTTON_STATE";
                case MtSSLMsgType.ORDER_RECEIVE:
                    return "ORDER_RECEIVE";
                case MtSSLMsgType.TEMPHUBSTATE:
                    return "TEMPHUBSTATE";
                case MtSSLMsgType.OPENBOXJOIN:
                    return "OPENBOXJOIN";
                case MtSSLMsgType.LOCKBOXJOIN:
                    return "LOCKBOXJOIN";
                case MtSSLMsgType.BOXDISPOSE:
                    return "BOXDISPOSE";
            }
            return "HEART_BEAT";
        }
    }
}